<template>
    <div id="addPermissionView">
        <!-- 
            permissionName:菜单权限名(String)
            permissionType:菜单权限类型(int) 1.按钮权限 2.菜单权限
            permissionUrl:权限对应url地址
            parentId:父菜单id
            plevel:菜单等级
            status:状态  0.禁用  1.启用
            sortNumber:排序号
            description:权限描述
         -->
        <table class="table table-bordered table-hover" >
             <tbody>
            <tr>
                <td>菜单权限名</td>
                <td>
                    <el-row >
                        <el-col :span="10">
                            <el-input v-model="dataSource.permissionName" placeholder="请输入内容"></el-input>
                        </el-col>
                    </el-row>
                </td>
                <td>菜单权限类型</td>
                <td>
                <el-row >
                    <el-col :span="10">
                         <el-select v-model="dataSource.permissionType" placeholder="请选择">
                            <el-option
                            v-for="item in permissionTypes"
                            :key="item.label"
                            :label="item.label"
                            :value="item.value">
                            </el-option>
                        </el-select>
                    </el-col>
                </el-row>
                </td>
            </tr>
            <tr>
                <td>权限对应url地址</td>
                <td>
                    <el-row >
                        <el-col :span="20">
                            <el-input v-model="dataSource.permissionUrl"></el-input>
                        </el-col>
                    </el-row>
                </td>
                <td>父菜单id</td>
                <td>
                    <el-row >
                        <el-col :span="10">
                            <el-select v-model="dataSource.parentId" placeholder="请选择">
                                <el-option
                                v-for="item in permissionList"
                                :key="item.value"
                                :label="item.permissionName"
                                :value="item.permissionId">
                                </el-option>
                            </el-select>
                        </el-col>
                    </el-row>
                </td>
            </tr>
            <tr>
                <td>菜单等级</td>
                <td>
                    <el-row >
                        <el-col :span="10">
                            <el-input v-model="dataSource.plevel"></el-input>
                        </el-col>
                    </el-row>
                </td>
                <td>状态</td>
                <td>
                    <el-row >
                        <el-col :span="10">
                            <el-input v-model="dataSource.status"></el-input>
                        </el-col>
                    </el-row>
                </td>
            </tr>
            <tr>
                <td>排序号</td>
                <td>
                     <el-row >
                        <el-col :span="10">
                            <el-input v-model="dataSource.sortNumber"></el-input>
                        </el-col>
                    </el-row>
                </td>
                <td>权限描述</td>
                <td>
                    <el-row >
                        <el-col :span="10">
                            <el-input v-model="dataSource.description"></el-input>
                        </el-col>
                    </el-row>
                </td>
            </tr>
             </tbody>
        </table>
        <el-row>
            <el-row>
                <el-button type="primary" @click="updatePermission">更新</el-button>
            </el-row>
        </el-row>
    </div>
</template>

<script>
import qs from 'qs'
export default {
    data(){
        return {
            permissionTypes: [{label: '按钮权限',value: 1},{label: '菜单权限',value:2}],
            permissionList: [],
            dataSource: {
                permissionName: '',
                permissionType: '',
                permissionUrl: '',
                parentId: '',
                plevel: 1,
                status: 1,
                sortNumber: 0,
                description: '',
                token: this.$token
            },
        }
    },
    methods: {
        updatePermission(){
            // /backstage/permission/update
            this.dataSource.token = this.$token;
            var url = window.baseURL + "/backstage/permission/update";
            this.$http.post(url,qs.stringify(this.dataSource))
            .then((response)=>{
                this.$router.go(-1);
            })
            .catch((error)=>{
            })
        }
    },
    created(){
        // 获取当前所有权限
        this.dataSource = JSON.parse(localStorage.getItem('currentPermission'));
        this.$http.get(window.baseURL+'/backstage/permission/findByPage?token='+this.$token)
        .then((response)=>{
            this.permissionList = response.data.data.list.results;
        })
        .catch((error)=>{

        })
    }
}
</script>

<style lang="scss" scoped>
    #addPermissionView {
        position: absolute;
        width: 100%;
        box-sizing: border-box;
        bottom: 0px;
        top: 40px;
        background: white;
        z-index: 101;
        padding: 50px;
        tr>td:nth-child(2n-1){
            text-align: center;
            vertical-align: middle;
        }
    }
</style>

